package com.caration.shell.item;

import android.content.ContentValues;
import android.graphics.Bitmap;

import com.caration.shell.Home;
import com.caration.shell.cr3d.GLHandler;
import com.caration.shell.workspace2D.ShellAppAppWidgetHostView;
import com.caration.shell.workspace3D.ShellRenderHost;
import com.caration.shell.workspace3D.WidgetsManager;
import com.caration.shell.workspace3D.de;

public class AppWidgetInfo extends ItemInfo {
	public int mWidgetId;
	public ShellAppAppWidgetHostView mHostView = null;
	public WidgetsManager mWidgetsManager;
	public de p;
	public Bitmap mIcon;
	public boolean r = false;
	public boolean s = false;
	private boolean t = false;
	private boolean isDisable = false;
	private Bitmap mBmp;
	private int mWidth;
	private int mHeight;
	private Runnable mRecycleBmpRun = new Runnable() {

		@Override
		public void run() {
			if (mBmp != null) {
				mBmp.recycle();
				mBmp = null;
			}
		}
	};

	public AppWidgetInfo(int itemType) {
		mItemType = itemType;
		mWidgetId = itemType;
		mWidgetsManager = ShellRenderHost.o();
	}

	public final Bitmap getBitmap(int width, int height) {
		GLHandler.removeCallbacks(mRecycleBmpRun);
		GLHandler.postDelayed(mRecycleBmpRun, 1000L);
		if ((mBmp == null) || (width != mWidth) || (height != mHeight)
				|| (mBmp.isRecycled())) {
			mRecycleBmpRun.run();
			mBmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
			mWidth = width;
			mHeight = height;
		}
		return mBmp;
	}

	@Override
	public void putValue(ContentValues contentvalues) {
		super.putValue(contentvalues);
		contentvalues.put("appWidgetId", Integer.valueOf(mWidgetId));
	}

	public final void c() {
		super.c();
	}

	public final void d() {
		this.t = true;
	}

	public final void e() {
		this.t = false;
		GLHandler.post(new Runnable() {

			@Override
			public void run() {
				mWidgetsManager.b(AppWidgetInfo.this);
			}
		});
	}

	public final boolean f() {
		return !t;
	}

	public final void disable() {
		isDisable = true;
	}

	public final void h() {
		GLHandler.post(new Runnable() {

			@Override
			public void run() {
				Home.getInstance().getWorkspace()
						.removeWidget(AppWidgetInfo.this);
				Home.getInstance().removeAppWidget(AppWidgetInfo.this);
				mHostView.f();
				mHostView = null;
			}
		});
		mWidgetsManager = null;
		if (this.p != null) {
			this.p.c();
			this.p = null;
		}
	}

	public final boolean isDisable() {
		return isDisable;
	}

	public final String toString() {
		return "AppWidget(id=" + Integer.toString(mWidgetId) + ")";
	}
}
